---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-pvc
  namespace: kubesphere-system
spec:
  accessModes:
  - ReadWriteOnce
{% if persistence.storageClass is defined and persistence.storageClass != "" %}
  storageClassName: {{ persistence.storageClass }}
{% endif %}
  resources:
    requests:
      storage: {% if redis_db_pv_size is defined %}{{ redis_db_pv_size }}{% else %}{{ common.redisVolumSize }}{% endif %}


---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: redis
    tier: database
    version: redis-4.0
  name: redis
  namespace: kubesphere-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
      tier: database
  template:
    metadata:
      labels:
        app: redis
        tier: database
        version: redis-4.0
    spec:
      containers:
      - image: {{ redis_repo }}:{{ redis_tag }}
        imagePullPolicy: IfNotPresent
        name: redis
        volumeMounts:
        - mountPath: /data
          name: redis-pvc
          subPath: redis-data
        ports:
        - containerPort: 6379
          protocol: TCP
        resources:
          limits:
            cpu: 1000m
            memory: 1000Mi
          requests:
            cpu: 20m
            memory: 100Mi
      volumes:
      - name: redis-pvc
        persistentVolumeClaim:
          claimName: redis-pvc
      tolerations:
        - key: node-role.kubernetes.io/master
          effect: NoSchedule
        - key: CriticalAddonsOnly
          operator: Exists
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            preference:
              matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: In
                values:
                - "" 


---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: redis
    tier: database
  name: redis
  namespace: kubesphere-system
spec:
  ports:
  - name: redis
    port: 6379
    protocol: TCP
    targetPort: 6379
  selector:
    app: redis
    tier: database
  sessionAffinity: None
  type: ClusterIP